<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加雇员</title>
    {% load static %}
    {% csrf_token %}
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
    <script src="/static/lib/layui/layui.js"></script>

    <link type="text/css" rel="stylesheet" href="/static/css/metroStyle.css">
    <link type="text/css" rel="stylesheet" href="/static/css/treeSelectStyle.css">
    <script src="/static/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.ztree.all.js"></script>
    <script type="text/javascript" src="/static/js/treeSelect.2.0.js"></script>
    <script type="text/javascript" src="/static/js/xm-select.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">
        <div class="layui-row layui-col-space10">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">雇员ID<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="user_code" placeholder="请输入雇员代码！(唯一值)" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
            </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">雇员姓名<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="username" placeholder="请输入雇员姓名！" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">身份证号<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="user_id" placeholder="请输入身份证号！" autocomplete="off" class="layui-input"
                       lay-verify="required|identity">
            </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">手机号<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="user_mobile" placeholder="请输入手机号码" autocomplete="off" class="layui-input"
                       lay-verify="required|phone">
            </div>
        </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">所属部门<span style="color: red">*</span></label>
            <div class="layui-input-block" name="dept" id="dept">

            </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">角色<span style="color: red">*</span></label>
            <div class="layui-input-block" id="role" name="role">

                </div>
        </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">邮箱<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input"
                       lay-verify="required|email">
            </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">岗位<span style="color: red">*</span></label>
            <div class="layui-input-block" id="job" name="job">

            </div>
        </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">是否签字<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="checkbox" name="is_sign" title="是/否">
            </div>
        </div>
        </div>
        <div class="layui-form-item layui-form-text" style="padding-top: 10px;">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark_describe" placeholder="请输入备注内容" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->
<script>
     layui.use(["okUtils", "form", "tree", "okLayer"], function () {

        let $ = layui.$;
        let form = layui.form;
        let okUtils = layui.okUtils;
        let okLayer = layui.okLayer;
        let tree = layui.tree;
        let util = layui.util;
        okLoading.close();

        form.on("submit(add)",function (data) {
            if(data.field.is_sign==="on"){
                data.field.is_sign=0;
            }else{
                data.field.is_sign=1;
            }
            okUtils.ajax("{% url 'users:users_insert' %}","post",data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
					parent.layer.close(parent.layer.getFrameIndex(window.name));
				});
            }).fail(function (error) {
                // 这里已经有提示了
            });
            return false;
        });

    });
</script>
<script type="text/javascript">
var demo3 = xmSelect.render({
	el: '#dept',
	radio: true,
    name:'dept',
    layVerify: 'required',
    prop:{
	    name:'dept_name',
        value:'id',
    },
	tree: {
		show: true,
		strict: true,
	},
	toolbar: {show: true},
	data: []
    });
    $.ajax({
        url: "{% url 'config:depts_list1' %}",
        type: "GET",
        success: function (ret) {
            var node = ret;
            demo3.update({
                data: node.data,
                autoRow: true,
                iconfont: {
                    parent: 'hidden',
                }
            })
        },
        error: function () {
        }
    });
</script>
<script>
    var demo1 = xmSelect.render({
		el: '#role',
		language: 'zn',
        layVerify: 'required',
        toolbar: {show: true},
		data: []
	})
    $.ajax({
        url: "{% url 'users:users_roles' %}",
        type: "GET",
        success: function (ret) {
            var node=ret;
            demo1.update({
                data:node.data,
                autoRow: true,
            })
        },
        error: function () {
        }
    });
</script>
<script>
    var demo2 = xmSelect.render({
		el: '#job',
        name:'jobs',
		language: 'zn',
        layVerify: 'required',
        filterable: true,
        paging: true,
        pageSize: 3,
        prop:{
	    name:'job_name',
        value:'id',
        },
        toolbar: {show: true},
		data: []
	})
    $.ajax({
        url: "{% url 'config:jobs_list1' %}",
        type: "GET",
        success: function (ret) {
            var node=ret;
            demo2.update({
                data:node.data,
                autoRow: true,
            })
        },
        error: function () {
        }
    });
</script>
</body>
</html>
